#
#
#
#
#

from direct.directbase import DirectStart
from direct.filter.CommonFilters import *
from time import time
from meshGen import MeshGenerator
from panda3d.core import ConfigVariableString
from random import randint

cubes = {}

for x in range(0, 25):
    cubes[x] = {}
    for y in range(0, 25):
        cubes[x][y] = {}
        for z in range(0, 25):
            cubes[x][y][z] = randint(1, 1)

ftime = time()            
mesh = MeshGenerator('world')

for j in cubes:
    for i in cubes[j]:
        for k in cubes[j][i]:

            id = cubes[j][i][k]
            
            if id == 0:
                continue
                
            if j-1 not in cubes or cubes[j-1][i][k] == 0:
                mesh.makeLeftFace(j, i, k, id)
            if j+1 not in cubes or cubes[j+1][i][k] == 0:
                mesh.makeRightFace(j, i, k, id)
            if i-1 not in cubes[j] or cubes[j][i-1][k] == 0:
                mesh.makeBackFace(j, i, k, id)
            if i+1 not in cubes[j] or cubes[j][i+1][k] == 0:
                
                mesh.makeFrontFace(j, i, k, id)
            if k-1 not in cubes[j][i] or cubes[j][i][k-1] == 0:
                mesh.makeBottomFace(j, i, k, id) 
            if k+1 not in cubes[j][i] or cubes[j][i][k+1] == 0:
                mesh.makeTopFace(j, i, k, id)
                
cube = render.attachNewNode(mesh.getGeomNode())
cube.setTexture(loader.loadTexture("Models/tex.png"))

print time() - ftime

#filters = CommonFilters(base.win, base.cam)
#filters.setBloom()
#render.setShaderAuto()
run()
